#pragma once
#include "Protocol.hpp"

class SvrCal
{
public:
    SvrCal() {}
    ~SvrCal() {}

    // 计算text中的数据
    string doCalculate(const string& text)
    {
        // 将从网络上来的数据，去掉报头
        string out;
        bool r = decode(text, &out);
        if(r == false)  return;

        // 反序列化
        Request req;
        r = req.deserialize(out);
        if(r == false)  return;

        // 计算结果
        Response resp = calHelper(req);

        // 序列化
        out = "";
        resp.serialize(&out);

        // 加上报头
        out = encode(out);

        return out;
    }
private:
    Response calHelper(Request& req)
    {   
        // 将Request转换为Response
        Response resp;
        switch (req._op)
        {
        case '+':
            resp._res = req._a + req._b;
            break;
        
        default:
            break;
        }
    }
};